package arithmetic.socket;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketAddress;

/**
 * @author jiangfeng 2019/7/17 22:37
 * socket 客户端
 */
public class SocketClientDemo {
    public static void main(String[] args) throws IOException, InterruptedException {


        int i=0;
        while (true) {
            // 与服务端建立连接
            Socket socket = new Socket("127.0.0.1",666);
            // 建立连接后获得输出流
            OutputStream outputStream = socket.getOutputStream();
            String message=(i++)+"客户端发送消息啊";
            outputStream.write(message.getBytes("UTF-8"));
            outputStream.close();
            socket.close();
            System.out.println("客户端发送信息"+message);
            Thread.sleep(2000);
        }



    }



}
